import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

const dealerRule = (resolve) => {
  import('views/dealerRule').then((module) => {
    resolve(module)
  })
}

const dealerRule1 = (resolve) => {
  import('views/dealerRule1').then((module) => {
    resolve(module)
  })
}

const application = (resolve) => {
  import('views/application').then((module) => {
    resolve(module);
  })
}

const upgrade = (resolve) => {
  import('views/upgrade').then((module) => {
    resolve(module);
  })
}

const upgradeCode = (resolve) => {
  import('views/upgradeCode').then((module) => {
    resolve(module);
  })
}

const exchange = (resolve) => {
  import('views/exchange').then((module) => {
    resolve(module);
  })
}

const exchangeHistory = (resolve) => {
  import('views/exchangeHistory').then((module) => {
    resolve(module);
  })
}

const dealer = (resolve) => {
  import('views/dealer').then((module) => {
    resolve(module)
  })
}

const viewRouter = new Router({
  routes: [
    {
      path: '/',
      component: dealerRule,
      meta: {
        title: '金至尊会员经销商'
      }
    },
    {
      path: '/application',
      component: application,
      meta: {
        title: '申请成为金至尊会员经销商'
      }
    },
    {
      path: '/dealer',
      component: dealer,
      meta: {
        title: '金至尊会员经销商'
      }
    },
    {
      path: '/upgrade',
      component: upgrade,
      meta: {
        title: '升级会员经销商'
      }
    },
    {
      path: '/upgradeCode',
      component: upgradeCode,
      meta: {
        title: '我的升级码'
      }
    },
    {
      path: '/exchange',
      component: exchange,
      meta: {
        title: '兑换金至尊会员升级码'
      }
    },
    {
      path: '/exchangeHistory',
      component: exchangeHistory,
      meta: {
        title: '兑换记录'
      }
    },
    {
      path: '/dealerRule',
      component: dealerRule,
      meta: {
        title: '经销商法则'
      }
    },
    {
      path: '/dealerRule1',
      component: dealerRule1,
      meta: {
        title: '经销商法则'
      }
    }
  ]
})

viewRouter.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title
  }
  let uid = to.query.uid || localStorage.getItem('uid');
  let token = to.query.token || localStorage.getItem('token');
  next()
  setTimeout(()=>{
    localStorage.setItem('uid', uid);
    localStorage.setItem('token', token);
  },40);
})


export default viewRouter
